/*
 * Sesame Inc.
 * Copyright (c) 2009 All Rights Reserved.
 */
package com.sesame.controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.ModelAndView;
import org.springframework.web.servlet.mvc.AbstractController;

import com.sesame.domain.Ask;
import com.sesame.service.PageService;
import com.sesame.service.UserService;
import com.sesame.toolkit.Page;

/**
 * @author voidman
 * 
 */
public class AskListController extends AbstractController {

    private UserService userService;
    private PageService pageService;

    public void setPageService(PageService pageService) {
        this.pageService = pageService;
    }

    public void setUserService(UserService userService) {
        this.userService = userService;
    }

    protected ModelAndView handleRequestInternal(HttpServletRequest request,
            HttpServletResponse response) throws Exception {

        // 分页相关
        String currentPage = request.getParameter("page");
        Page page = pageService.paging(request, currentPage, new Integer(10));
        page.setRecordCount(userService.getAskCount());

        Map model = new HashMap();
        List<Ask> askList = userService.listAsk(page);
        model.put("askList", askList);
        model.put("page", page);

        return new ModelAndView("askList", model);

    }

}